package com.zw.yzk.kabu.data.repository;

import com.zw.yzk.kabu.data.network.task.Task;
import com.zw.yzk.kabu.data.constant.Constant;
import com.zw.yzk.kabu.data.network.ServiceGenerator;
import com.zw.yzk.kabu.data.network.entity.ForgetPasswordEntity;
import com.zw.yzk.kabu.data.network.service.ForgetPasswordService;
import com.zw.yzk.kabu.data.network.task.ForgetPasswordTask;

import javax.inject.Inject;

import rx.Observable;
import rx.functions.Func1;

/**
 * Created by zhanwei on 2016/12/24.
 */

public class ForgetPasswordRepository extends CommonRepository {

    @Inject
    public ForgetPasswordRepository() {

    }

    @Override
    protected Observable connectServer(Task task) {
        ForgetPasswordService loginService = ServiceGenerator.createService(ForgetPasswordService.class);
        ForgetPasswordTask forgetPasswordTask = (ForgetPasswordTask) task;

        return loginService.forgetPassword(forgetPasswordTask.account, forgetPasswordTask.token, forgetPasswordTask.verifyCode);
    }

    @Override
    protected Func1<ForgetPasswordEntity, Observable> getServerData() {
        return new Func1<ForgetPasswordEntity, Observable>() {
            @Override
            public Observable call(ForgetPasswordEntity entity) {
                return Observable.just(entity.errCode == Constant.RESULT_OK);
            }
        };
    }

}
